package com.padbot.qm.security;

import com.padbot.qm.util.Constants;

public class UserSessionToken {
	
	private long lifecycle = Long.valueOf(Constants.get("session.timeout"));
	
	private long createTime = System.currentTimeMillis();
	
	private long updateTime = System.currentTimeMillis();
	

	public UserSessionToken() {
	}
	
	public long getLifecycle() {
		return lifecycle;
	}

	public void setLifecycle(long lifecycle) {
		this.lifecycle = lifecycle;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public long getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(long updateTime) {
		this.updateTime = updateTime;
	}

	public boolean isActive(){
		long current = System.currentTimeMillis();
		boolean isActive = (current - updateTime) < lifecycle;
		if(isActive){
			update();
		}
		return isActive;
	}
	
	private void update(){
		this.updateTime = System.currentTimeMillis();
	}

}
